<template>
	<el-form label-width="120px" :model="form" :rules="rules" ref="queryForm" @submit.prevent>

		<el-form-item label="行政区域" prop="district">
			<el-select v-model="form.district" size="default" placeholder="请选择" style="width:200px" clearable
				filterable>
				<el-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel"
					:value="item.dictValue" />
			</el-select>
		</el-form-item>

		<el-row>
			<el-col :span="24">
				<el-form-item label="群名称" prop="name">
					<el-input v-model="form.name" style="width:200px;"></el-input>
				</el-form-item>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="24">
				<el-form-item label="指挥单位" prop="zhdw">
					<el-input v-model="form.zhdw" style="width:200px;"></el-input>
				</el-form-item>
			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-form-item label="副指挥单位" prop="fzhdw">
					<el-input v-model="form.fzhdw" style="width:200px;"></el-input>
				</el-form-item>
			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-form-item label="平时部署位置" prop="zsbswz">
					<el-input v-model="form.zsbswz" style="width:200px;"></el-input>
				</el-form-item>
			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-form-item label="战时部署位置" prop="psbswz">
					<el-input v-model="form.fzhdw" style="width:200px;"></el-input>
				</el-form-item>
			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-form-item label="部署类型" prop="bslx">
					<el-select v-model="form.bslx" size="default" placeholder="请选择" style="width:200px" clearable
						filterable>
						<el-option label="重要目标" value="重要目标" />
						<el-option label="人员防护" value="人员防护" />
						<el-option label="跨区域支援" value="跨区域支援" />
						<el-option label="政治工作计划" value="政治工作计划" />
					</el-select>
				</el-form-item>
			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-form-item label="人员编成" prop="bc">
					<el-input v-model="form.bc" style="width:200px;" type="textarea" rows="8"></el-input>
				</el-form-item>
			</el-col>
		</el-row>

		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>

	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'options'])

	const form = ref({
		name: ''
	})

	const queryForm = ref('')

	const options = ref([])

	//必填项
	const rules = reactive({
		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}],
		district: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "change"
		}]

	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zhyd/fkllbc/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		options.value = props.options
		if (props.editData) form.value = props.editData
	})
</script>

<style lang="scss" scoped>
</style>